package xju_5_6.entity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

@Component
public class Teacher {
    @Value("Web")
    private String msg;
    // 默认根据类型
    @Autowired
    @Qualifier("student")
    // 默认更具名称注入
//    @Resource
    private Student student;

    public Teacher() {
        System.out.println("teacher constructor 创建了");
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    // 普通方法
    public void teach(){
        System.out.println("teacher teach -"+msg);
    }

    @PostConstruct
    public void init(){
        System.out.println("teacher init ");
    }
    @PreDestroy
    public void destroy(){
        System.out.println("teacher destroy");
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "msg='" + msg + '\'' +
                ", student=" + student +
                '}';
    }
}
